/*
 * dev_epwm.cpp
 *
 *  Created on: 2013-8-16
 *      Author: test
 */


#include "dev_epwm.h"
#include "DSP2833x_Device.h"

volatile unsigned short* const epwm1_reg_tbprd	= (volatile unsigned short*)&EPwm1Regs.TBPRD;
volatile unsigned short* const epwm1_reg_tbphs	= (volatile unsigned short*)&EPwm1Regs.TBPHS.all;
volatile unsigned short* const epwm1_reg_tbctr	= (volatile unsigned short*)&EPwm1Regs.TBCTR;
volatile unsigned short* const epwm1_reg_tbctl 	= (volatile unsigned short*)&EPwm1Regs.TBCTL.all;
volatile unsigned short* const epwm1_reg_tbsts	= (volatile unsigned short*)&EPwm1Regs.TBSTS.all;

volatile unsigned short* const epwm1_reg_cmpa = (volatile unsigned short*)&EPwm1Regs.CMPA.half.CMPA;
volatile unsigned short* const epwm1_reg_cmpb = (volatile unsigned short*)&EPwm1Regs.CMPB;
volatile unsigned short* const epwm1_reg_cmpctl = (volatile unsigned short*)&EPwm1Regs.CMPCTL.all;
volatile unsigned short* const epwm1_reg_cmpahr = (volatile unsigned short*)&EPwm1Regs.CMPA.half.CMPAHR;

volatile unsigned short* const epwm1_reg_aqctla = (volatile unsigned short*)&EPwm1Regs.AQCTLA.all;
volatile unsigned short* const epwm1_reg_aqctlb = (volatile unsigned short*)&EPwm1Regs.AQCTLB.all;
volatile unsigned short* const epwm1_reg_aqsfrc = (volatile unsigned short*)&EPwm1Regs.AQSFRC.all;
volatile unsigned short* const epwm1_reg_aqcsfrc = (volatile unsigned short*)&EPwm1Regs.AQCSFRC.all;

volatile unsigned short* const epwm1_reg_dbctl = (volatile unsigned short*)&EPwm1Regs.DBCTL.all;
volatile unsigned short* const epwm1_reg_dbred = (volatile unsigned short*)&EPwm1Regs.DBRED;
volatile unsigned short* const epwm1_reg_dbfed = (volatile unsigned short*)&EPwm1Regs.DBFED;

volatile unsigned short* const epwm1_reg_pcctl = (volatile unsigned short*)&EPwm1Regs.PCCTL.all;

volatile unsigned short* const epwm1_reg_tzsel = (volatile unsigned short*)&EPwm1Regs.TZSEL.all;
volatile unsigned short* const epwm1_reg_tzctl = (volatile unsigned short*)&EPwm1Regs.TZCTL.all;
volatile unsigned short* const epwm1_reg_tzeint = (volatile unsigned short*)&EPwm1Regs.TZEINT.all;
volatile unsigned short* const epwm1_reg_tzflg = (volatile unsigned short*)&EPwm1Regs.TZFLG.all;
volatile unsigned short* const epwm1_reg_tzclr = (volatile unsigned short*)&EPwm1Regs.TZCLR.all;
volatile unsigned short* const epwm1_reg_tzfrc = (volatile unsigned short*)&EPwm1Regs.TZFRC.all;

volatile unsigned short* const epwm1_reg_etsel = (volatile unsigned short*)&EPwm1Regs.ETSEL.all;
volatile unsigned short* const epwm1_reg_etps = (volatile unsigned short*)&EPwm1Regs.ETPS.all;
volatile unsigned short* const epwm1_reg_etflg = (volatile unsigned short*)&EPwm1Regs.ETFLG.all;
volatile unsigned short* const epwm1_reg_etclr = (volatile unsigned short*)&EPwm1Regs.ETCLR.all;
volatile unsigned short* const epwm1_reg_etfrc = (volatile unsigned short*)&EPwm1Regs.ETFRC.all;

void epwm_init(){
	EALLOW;
	SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;
	EDIS;
}

void epwm1_init(){
	EALLOW;
	SysCtrlRegs.PCLKCR1.bit.EPWM1ENCLK = 1;
	EDIS;

//	   EPwm1Regs.ETSEL.bit.SOCAEN = 1;        // Enable SOC on A group
//	   EPwm1Regs.ETSEL.bit.SOCASEL = 4;       // Select SOC from from CPMA on upcount
//	   EPwm1Regs.ETPS.bit.SOCAPRD = 1;        // Generate pulse on 1st event
//	   EPwm1Regs.CMPA.half.CMPA = 0x0080;	  // Set compare A value
//	   EPwm1Regs.TBPRD = 0xFFFF;              // Set period for ePWM1
//	   EPwm1Regs.TBCTL.bit.CTRMODE = 0;		  // count up and start
}
